package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程计划管理相关的接口
 */
@Api(value = "课程计划管理相关的接口",tags = "课程计划管理相关的接口")
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;

    /**
     * 查询课程计划树形结构
     * @param courseId
     * @return
     */
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    @ApiOperation("查询课程计划树形结构")
    public List<TeachplanDto> getTreeNodes(@PathVariable("courseId") Long courseId){

        return teachplanService.findTeachplanTree(courseId);
    }

    /**
     * 新增或修改课程计划
     * @param teachplanDto
     * @return
     */
    @PostMapping("/teachplan")
    public TeachplanDto saveOrUpdateTeachplan(@RequestBody TeachplanDto teachplanDto){

        TeachplanDto teachplanDto1 = teachplanService.saveOrUpdateTeachplan(teachplanDto);
        return teachplanDto1;
    }


    /**
     * 删除课程计划
     * @param id
     * @return
     */
    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{id}")
    public List<TeachplanDto> deleteTeachplanDto(@PathVariable("id") Long id){

        List<TeachplanDto> teachplanDtos = teachplanService.deleteTeachplanDto(id);
        return teachplanDtos;
    }


    /**
     * 课程计划排序--上移
     * @param id
     * @return
     */
    @ApiOperation("课程计划排序--上移")
    @PostMapping("/teachplan/moveup/{id}")
    public String moveupTeachplan(@PathVariable("id") Long id){

        return teachplanService.moveupTeachplan(id);
    }

    /**
     * 课程计划排序--下移
     * @param id
     * @return
     */
    @ApiOperation("课程计划排序--下移")
    @PostMapping("/teachplan/movedown/{id}")
    public String movedownTeachplan(@PathVariable("id") Long id){

        return teachplanService.movedownTeachplan(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息的解绑")
    @DeleteMapping("/teachplan/association/media/{teachplanId}/{mediaId}")
    public void delAssociationMedia(@PathVariable("teachplanId") Long teachplanId, @PathVariable("mediaId") String mediaId){
        teachplanService.delAssociationMedia(teachplanId,mediaId);
    }

}
